package com.edu.chongdian;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.GridView;

import com.edu.chongdian.viewmodels.VirtualCurrencyManager;

import java.util.ArrayList;
import java.util.List;

public class chongdianActivity extends AppCompatActivity {

    private int[] mBalanceOptions = new int[]{2,3,4,5,6,7,8,9,10,11,12};
    BalanceAdapter adapter;
    Button button;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chongdian);
        button=findViewById(R.id.con_button);
        initView();
    }
    private void initView(){
        GridView gridView = findViewById(R.id.grid_view);
        adapter = new BalanceAdapter(this, mBalanceOptions);
        gridView.setAdapter(adapter);
        adapter.setSelectedPosition(0);
        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                switch (position){
                    case 0:
                        adapter.setSelectedPosition(0);
                        show1(mBalanceOptions[0]);
                        break;
                    case 1:
                        adapter.setSelectedPosition(1);
                        show1(mBalanceOptions[1]);
                        break;
                    case 2:
                        adapter.setSelectedPosition(2);
                        show1(mBalanceOptions[2]);
                        break;
                    case 3:
                        adapter.setSelectedPosition(3);
                        show1(mBalanceOptions[3]);
                        break;
                    case 4:
                        adapter.setSelectedPosition(4);
                        show1(mBalanceOptions[4]);
                        break;
                    case 5:
                        adapter.setSelectedPosition(5);
                        show1(mBalanceOptions[5]);
                        break;
                    case 6:
                        adapter.setSelectedPosition(6);
                        show1(mBalanceOptions[6]);
                        break;
                }
            }
        });
    }
    private void show1(int num){
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                VirtualCurrencyManager virtualCurrencyManager = new VirtualCurrencyManager();
                int userId = 12345;
                int consume = virtualCurrencyManager.consumeVirtualCurrency(userId, num);// 消费30元，假设消费成功并返回true
                Log.e("TAG","消费结果"+consume);
            }
        });
    }
}